<?php
namespace app\admin\logic;


//品牌页
use think\facade\Request;

class BrandLogic{
    //留值
    public static function brandData(){
        $param=Request::param();
        $data=[
            'keywords'=>isset($param['keywords'])?$param['keywords']:'',
            'recommended'=>isset($param['recommended'])?$param['recommended']:'',
            'if_show'=>isset($param['if_show'])?$param['if_show']:[],
            'logo'=>isset($param['logo'])?$param['logo']:[],
        ];
        return $data;
    }
    //where语句拼接
    public static function brandWhere(){
        $param=Request::param();
        $where=[];
        $whereOr=[];
        if (isset($param['keywords']) && !empty($param['keywords'])){
            $where[]=['brand_name','like','%'.$param['keywords'].'%'];
        }
        if (isset($param['recommended']) && $param['recommended']<>''){
            $where[]=['recommended','=',$param['recommended']];
        }
        if (isset($param['if_show']) && count($param['if_show'])=='1'){
            $where[]=['if_show','=',$param['if_show'][0]];
        }
        if (isset($param['logo']) && count($param['logo'])=='1'){
            $str=implode($param['logo']);
            if ($str=='1'){
                $where[]=['brand_logo','<>',''];
            }else if($str=='0'){
                $whereOr[]=['brand_logo','=',''];
                $whereOr[]=['brand_logo','=',null];
            }
        }
        return [$where,$whereOr];
    }

    //品牌添加
     public static function   brandAdd($post){
         $if_show=isset($post['if_show'])?$post['if_show']:'';
         $recommended=isset($post['recommended'])?$post['recommended']:'';
         $data=[
             'brand_name'=>$post['name'],
             'sort_order'=>$post['sort'],
             'recommended'=>$recommended,
             'if_show'=>$if_show,
             'tag'=>$post['tags']
         ];
         return $data;

         }
         //品牌修改
          public static function   brandEdit($post){
              $if_show=isset($post['if_show'])?$post['if_show']:'';
              $recommended=isset($post['recommended'])?$post['recommended']:'';
              $data=[
                  'brand_id'=>$post['bid'],
                  'brand_name'=>$post['name'],
                  'sort_order'=>$post['sort'],
                  'recommended'=>$recommended,
                  'if_show'=>$if_show,
                  'tag'=>$post['tags']
              ];
              return $data;
              }





}